package com.huluobo.a2211mdmdemo

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.max

/**
 *  Created by LC on 2025/4/22.
 */

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun demo02() {
    val list = listOf(
        "咖啡",
        "Java基础",
        "Kotlin基础,从入门到放弃,Kotlin基础,从入门到放弃,Kotlin基础,从入门到放弃,Kotlin基础,从入门到放弃",
        "咖啡",
        "咖啡",
        "Java基础",
        "Kotlin基础,从入门到放弃",
        "咖啡",
        "咖啡",
        "Java基础",
        "Kotlin基础,从入门到放弃",
        "咖啡"
    )

    FlowRow(
        Modifier.padding(10.dp),
        horizontalArrangement = Arrangement.spacedBy(10.dp),
        verticalArrangement = Arrangement.spacedBy(10.dp)
    ) {
        list.forEach {
            FlowItem(text = it)
        }
    }
}

@Composable
fun FlowItem(text: String) {
    Text(
        text = text, modifier = Modifier
            .background(Color.Green, RoundedCornerShape(20.dp))
            .border(
                1.dp, Color.Gray,
                RoundedCornerShape(20.dp)
            )
            .padding(horizontal = 10.dp, vertical = 5.dp), maxLines = 1, overflow = TextOverflow.Ellipsis
    )
}